'use strict'
import React, {Component} from 'react'
import {Link} from 'react-router'
import Header from './Common/Header'
import {viewerImg, browser} from '../Tools'

export default class NtcDetailFile extends Component {
    constructor(props) {
        super(props)
        this.filetype = '';
    }

    componentWillMount() {
        //只有苹果浏览器或安卓APP进入此页面
        const {name} = this.props.params;
        let type = name.substring(name.lastIndexOf('.') + 1);
        switch (type) {
            case 'jpg':
                type = 'image'
                break;
            case 'jpeg':
                type = 'image'
                break;
            case 'png':
                type = 'image'
                break;
            case 'bmp':
                type = 'image'
                break;
            case 'gif':
                type = 'image'
                break;
            case 'pdf':
                type = 'office'
                break;
            case 'xls':
                type = 'office'
                break;
            case 'xlsx':
                type = 'office'
                break;
            case 'doc':
                type = 'office'
                break;
            case 'docx':
                type = 'office'
                break;
            case 'ppt':
                type = 'office'
                break;
            case 'pptx':
                type = 'office'
                break;
            default:
                type = ''
                break;
        }
        this.filetype = type
    }

    render() {
        const {name, url} = this.props.params;
        let downlink = <a className='h_link hlinkfile' href={url + '&app=true&appdown=true&filename=' + encodeURIComponent(name)}/>
        if (sessionStorage.weixin == 'true')
            downlink = null
        return (
            <div className='pjb_filedown'>
                <Header title={name} link={downlink}/> {this.filetype == 'image'
                    ? <div className='ntcfileimg'><img className='imgdown' src={url} alt='图片地址有误' onClick={viewerImg.bind(this, 'src')}/></div>
                    : <div>
                        {browser().iPhone && this.filetype == 'office'
                            ? <iframe src={url} id='fileiframe'></iframe>
                            : <div className='filedntip'>此附件暂不支持预览<br/>请用安卓客户端下载</div>}
                    </div>
}

            </div>
        )
    }
}
